program test
  implicit double complex (a-h,o-q,s-z)
  implicit real*8 (r)
  parameter(nsegm=20,ncacm=30,ngam=1000,nspm=1000)
  parameter(nmax=2000,maxs=250,neqd=nmax,mni=3000,mnia=300)
  parameter(mxrd=1000,maxd=500,nkmax=30,nbase=1000,maxc=nbase)
  parameter(ngauss=32)
  dimension scawf(1000)
! ksq= will be used for ksquare cal.
  dimension rgaussx1(ngauss),rgaussw1(ngauss), &
               rgaussx2(ngauss),rgaussw2(ngauss),&
              up(ngauss),u(ngauss),v_ws(ngauss)

  !  double complex v_0,a,v_so,esw
  cweight=1.d0
  rrxmax=25.d0
  rixass=5.d0
  rrstep=0.1d0
  rmatch=1.5d0
  mnbo=5
  icore=1
  npar=1
  at=16.d0
  zt=8.d0
  r_0=1.275d0
  rolrtol=1.d-12
  igam=0
  lipnip=1
  jipnip=3
  v_0=52.109d0
  a=0.7d0
  v_so=20.715d0
 !esw=cmplx(4.d0,-0.d0)
  esw=cmplx(-5.d0,-0.1)
  call gauleg(0.d0,rrxmax,rgaussx1,rgaussw1,ngauss)
  call swf(rrxmax,rixass,rrstep,rmatch,mnbo,icore,npar,at,zt,v_0,r_0,a,v_so,rolrtol,igam,lipnip,jipnip,esw,scawf,ck,dwght,coul,rgaussx1,u,up,ngauss,v_ws)
  write(*,*) esw
!!$  do i=1,250
!!$     write(*,*) scawf(i)
!!$  end do
end program test

!=======================================================================
! Taken from the Numerical Recipes. Calculates the weigts and points
! for the gauss integration method. Note: It converts the integration
! limits between (-1,1)
	SUBROUTINE gauleg(x1,x2,x,w,n)
	INTEGER n
	REAL*8 x1,x2,x(n),w(n)
	DOUBLE PRECISION EPS	!is the relative precision
	PARAMETER (EPS=3.d-14)
	INTEGER i,j,m
	DOUBLE PRECISION p1,p2,p3,pp,xl,xm,z,z1
	m=(n+1)/2 !the roots are symetrics, son it calculates the half
	xm=0.5d0*(x2+x1)
	xl=0.5d0*(x2-x1)
	do 12 i=1,m
	 z=cos(3.141592654d0*(i-.25d0)/(n+.5d0))
 1	 continue
	 p1=1.d0
	 p2=0.d0
	 do 11 j=1,n
          p3=p2
	  p2=p1
	  p1=((2.d0*j-1.d0)*z*p2-(j-1.d0)*p3)/j
 11	 continue
	 pp=n*(z*p1-p2)/(z*z-1.d0)
	 z1=z
	 z=z1-p1/pp
	 if(abs(z-z1).gt.EPS)goto 1
	 x(i)=xm-xl*z
	 x(n+1-i)=xm+xl*z
	 w(i)=2.d0*xl/((1.d0-z*z)*pp*pp)
	 w(n+1-i)=w(i)
 12	continue
	return
	END
